<?php

namespace app\models\distribution;

use Yii;

/**
 * This is the model class for table "distribution_basic".
 *
 * @property int $id
 * @property int $svip2 svip2 比例
 * @property int $svip3_ svip3+比例
 */
class DistributionBasic extends \yii\db\ActiveRecord
{
    /**
     * {@inheritdoc}
     */
    public static function tableName()
    {
        return 'distribution_basic';
    }

    /**
     * {@inheritdoc}
     */
    public function rules()
    {
        return [
            [['svip2', 'svip3_'], 'integer'],
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'svip2' => 'Svip2',
            'svip3_' => 'Svip3',
        ];
    }

    public static function getLastOne()
    {
        $model = self::find()
            ->orderBy(['id' => SORT_DESC])
            ->one();

        if (!$model) {
            $model = new self();
        }

        return $model;
    }

    public static function saveData($data)
    {
        $model = self::getLastOne();

        if ($model->load(['DistributionBasic' => $data]) && $model->save()) {
            return true;
        }
    }
}
